﻿using Azure.Core;
using HealthcareSystem.API.Write.Application.Command.EquipmentCommand;
using HealthcareSystem.Domain.BasicSettings.Equipment;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.EquipmentCommandHandler
{
    /// <summary>
    /// 设备修改请求
    /// </summary>
    public class UpdateEquipmentCommandHandler : IRequestHandler<UpdateEquipmentCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<EquipmentTable> equipRep;

        public UpdateEquipmentCommandHandler(IBaseRepository<EquipmentTable> equipRep)
        {
            this.equipRep = equipRep;
        }
        public async Task<ApiResult<int>> Handle(UpdateEquipmentCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code=ResultCode.查询成功;
            result.Message=ResultCode.查询成功.ToString();

            var res=equipRep.GetAll().FirstOrDefault(x=>x.EquipmentId==request.EquipmentId);
            res.EquipmentBrand=request.EquipmentBrand;
            res.EquipmentName=request.EquipmentName;
            res.EquipmentCoding=request.EquipmentCoding;
            res.EquipmentType=request.EquipmentType;
            res.EquipmentSNnum=request.EquipmentSNnum;
            res.EquipmentStatus=request.EquipmentStatus;
            await equipRep.UpdAsync(res);
            return await Task.FromResult(result);
        }
    }
}
